package com.cp.yn.activity

import android.os.Bundle
import com.common.base.base.BaseActivity
import com.common.base.tools.extend.click
import com.common.base.tools.utils.language.LanguageType
import com.common.base.tools.utils.language.MultiLanguageUtil
import com.cp.yn.R
import com.cp.yn.databinding.ActivityLanguageBinding
import com.cp.yn.manager.RouterManager
import com.didi.drouter.annotation.Router

@Router(path = RouterManager.Path.APP_Language)
class LanguageActivity : BaseActivity<ActivityLanguageBinding>() {
    var languageType = MultiLanguageUtil.getInstance().languageType

    override fun viewBinding(): ActivityLanguageBinding {
        return ActivityLanguageBinding.inflate(layoutInflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        when (languageType) {
            LanguageType.LANGUAGE_FOLLOW_SYSTEM -> viewBinding.radioGroup.check(R.id.radio_system)
            LanguageType.LANGUAGE_CHINESE_SIMPLIFIED -> viewBinding.radioGroup.check(R.id.radio_zh)
            LanguageType.LANGUAGE_EN -> viewBinding.radioGroup.check(R.id.radio_en)
        }

        viewBinding.radioGroup.setOnCheckedChangeListener { group, checkedId ->
            when (checkedId) {
                R.id.radio_system -> languageType = LanguageType.LANGUAGE_FOLLOW_SYSTEM
                R.id.radio_zh -> languageType = LanguageType.LANGUAGE_CHINESE_SIMPLIFIED
                R.id.radio_en -> languageType = LanguageType.LANGUAGE_EN
            }
        }

        viewBinding.languageConfirm.click {
            MultiLanguageUtil.getInstance().updateLanguage(languageType, baseActivity)
        }
    }
}

